<?php

require_once 'Ext/User/Action/Edit/Email/Interface.php';

class Ext_User_Action_Edit_Email_Adapter_Ucenter extends Ext_User_Action_Edit_Email_Abstract
{
    public function editEmail($email)
    {
        $_appModelDbTableUserAccountBaseUsername = App_Model_DbTable_User_Account_Base_Username::getInstance();
        $_userAccountBaseUsernameRow = $_appModelDbTableUserAccountBaseUsername->getRowByUserId($this->_userId);
        if(!isset($_userAccountBaseUsernameRow['username']) || $_userAccountBaseUsernameRow['username'] == '')
        {
            $_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_RECORD_NOT_FONUD);
            return $_result;
        }
        $_username = $_userAccountBaseUsernameRow['username'];
        $_extAccountUcenter = new Ext_Account_Ucenter();
        $uid = $_extAccountUcenter->changeEmail($_username, $email);

	    if($uid > 0) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::SUCCESS);
            return $_result;
	    } elseif($uid == 0) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::SUCCESS);
            return $_result;
		} elseif($uid == -4) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_EMAIL_FORMAT_ERROR);
            return $_result;
		} elseif($uid == -5) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_EMAIL_IS_DENIED);
            return $_result;
		} elseif($uid == -6) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_EMAIL_ALREADY_EXISTS);
            return $_result;
		} elseif($uid == -7) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_NOTHING);
            return $_result;
		} elseif($uid == -8) {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_USER_IS_PROTECTED);
            return $_result;
		} else {
			$_result = $this->setResult(Ext_User_Action_Edit_Email_Result::FAILURE_UNCATEGORIZED);
            return $_result;
		}

    }

}
